﻿using Smobiler.Core;
using Smobiler.Core.Controls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Model;
using DAL;
using FubiManger.Pad;
using FubiManger.UI;
using System.Data;

namespace FubiManger.Cashier
{
    partial class CashierForm : Smobiler.Core.Controls.MobileForm
    {
        public CashierForm() : base()
        {
            //This call is required by the SmobilerForm.
            InitializeComponent();
        }
        /// <summary>
        /// 商户ID
        /// </summary>
        public string merchantid { get; set; }
        /// <summary>
        /// 用户ID
        /// </summary>
        public string adminid { get; set; }
        /// <summary>
        /// 订单集合
        /// </summary>
        private List<ms_order> hourlist = new List<ms_order>();
        private void panclose_Press(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnfood_Press(object sender, EventArgs e)
        {
            List<ms_disk> disklist = diskDal.Querybymerid(merchantid);
            if (disklist.Count > 0)
            {
                DisksForm frm = new DisksForm();
                frm.merchantid = merchantid;//商户id
                frm.adminid = adminid;//用户ID
                this.Form.Show(frm, true);
            }
            else
            {
                OrderfoodForm frm = new OrderfoodForm();
                frm.merchantid = merchantid;//商户id
                frm.adminid = adminid;//用户ID
                this.Form.Show(frm, true);
            }
        }

        private void CashierForm_Load(object sender, EventArgs e)
        {
            hourlist = orderDal.QuerybyHour(merchantid,"2");//实时订单
            Getorder(hourlist);
        }

        /// <summary>
        /// 获取订单
        /// </summary>
        private void Getorder(List<ms_order> ordlist)
        {
            
            if (lvorder.Rows.Count > 0)
                lvorder.Rows.Clear();
            DataTable table = new DataTable();
            table.Columns.Add("nickname");
            table.Columns.Add("ordid");
            table.Columns.Add("ordsn");
            table.Columns.Add("time");
            table.Columns.Add("disksn");
            table.Columns.Add("u_sage");
            table.Columns.Add("is_online");
            table.Columns.Add("stype");
            for (int i = 0; i < ordlist.Count; i++)
            {
                string nickname = "";
                if (ordlist[i].user_tel.Length == 11)
                    nickname = ordlist[i].user_tel.Substring(0, 3) + "****" + ordlist[i].user_tel.Substring(7, 4);
                table.Rows.Add(nickname, ordlist[i].id, ordlist[i].order_sn, ordlist[i].add_time, ordlist[i].orderdisksn, ordlist[i].u_sage, ordlist[i].is_online, "1");
            }
            lvorder.DataSource = table;
            lvorder.DataBind();
           
        }
        /// <summary>
        /// 刷新
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void lvorder_Refresh(object sender, EventArgs e)
        {
            hourlist = orderDal.QuerybyHour(merchantid,"2");//实时订单
            Getorder(hourlist);
        }
        /// <summary>
        /// 刷新
        /// </summary>
        public void Resfh()
        {
            hourlist = orderDal.QuerybyHour(merchantid,"2");//实时订单
            Getorder(hourlist);
        }
        private void btnoff_Press(object sender, EventArgs e)
        {
            Write_offcontrol con = new Write_offcontrol();
            con.merchantid = merchantid;//商户ID
            this.Form.ShowDialog(con);
        }
    }
}